<h1> Modules Manage </h1>

<div class="breadcrumb">
        <a href="/admin/index">Home</a>
         :: <a href="/admin/module">Modules</a>
</div>
<div class="box">
 	<div class="heading">
      <h1><img alt="" src="/images/admin/module.png"> Modules</h1>
    </div>
    <div class="content">
      	<table class="list">
		    <?php if(isset($this->widgets) && $this->widgets!=null) 
		    { ?>
	        <thead>
	          <tr>
	          	<td class="left">No</td>
	            <td class="left">Module Name</td>
	            <td class="left">Position</td>
	            <td class="left">Sort Order</td>
	            <td class="right">Action</td>
	          </tr>
	        </thead>
	        <tbody>
		         <?php $i=0;
					foreach ($this->widgets as $widget) 
					{ $i++;?>
		          		<tr>
				          	<td class="left"><?php echo $i;?></td>
				            <td class="left"><?php  echo $widget["module_title"];?></td>
				            <?php 
				            if($widget["module_sort"] >= 0)  
				            {?>
					            <td class="left"><?php  echo $widget["module_type"];?></td>
					            <td class="left"><input type = "text" maxlength="2" id = "<?php  echo $widget["module_code"];?>" value="<?php  echo $widget["module_sort"];?>" name = "sort_order" size="50"></input></td>
				            <?php 
				            } 
				            else 
				            {?>
					            <td class="left"></td>
					            <td class="left"><input type = "text" maxlength="2" id = "<?php  echo $widget["module_code"];?>" name = "sort_order" value = "" size="50"></input></td>
				            <?php 
				            }?>
				            
				            <td class="right">
				             <?php 
				             if($widget["module_sort"] < 0)  
				             {?>
				             	[ <a href = "javascript:;" onclick="InstallModule('<?php  echo $widget["module_code"];?>')">install</a> ]
				             <?php 
				             } 
				             else 
				             {?>
				             	[ <a href = "javascript:;" onclick="UpdateModule('<?php  echo $widget["module_code"];?>')">Update</a> ]
				            	[ <a href = "javascript:;" onclick="UnInstallModule('<?php  echo $widget["module_code"];?>')">Uninstall</a> ]
				             <?php 
				             }?>
				            </td>
			          	</tr>
		          <?php }?>
	        </tbody>
	       	<?php 
		    } 
	       	else 
	       	{?>
	        <div style="text-align: center;padding-top:100px;">No Module found!</div>
       		<?php 
	       	}?>
      	</table>
    </div>
</div>

<script type="text/javascript">
function InstallModule(module_code)
{ 
	var abc= document.getElementById(String(module_code)).value ;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			if(xmlhttp.responseText == "-1")
			{
				alert("There was an error during install");
			}
			else if(xmlhttp.responseText == "-2" )
			{
				alert("You did not enter Sort Module");
			}
			else if(xmlhttp.responseText == "-3")
			{
				alert("Sort Module may only enter >=0");
			}
			else if(xmlhttp.responseText == "-4")
			{
				alert("Sequence number already exists");
			}
			else if(xmlhttp.responseText == "-5")
			{
				alert("You don`t have permission to manipulate the Widget Module");
			}
			else
			{
				window.location="/admin/module";
			}
		}	
	};
	var url = "<?php echo $this->installUrl?>?module="+module_code+"&sort="+abc;
	xmlhttp.open("GET",url,true);	
	xmlhttp.send();
	return false;
}
function UnInstallModule(module_code)
{
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			if(xmlhttp.responseText == "-1")
			{
				alert("There was an error during install");
			}
			else if(xmlhttp.responseText == "-2")
			{
				alert("You don`t have permission to manipulate the Widget Module");
			}
			else
			{			
				window.location="/admin/module";
			}
		}	
	};
	var url = "<?php echo $this->unInstallUrl?>?module="+module_code;
	xmlhttp.open("GET",url,true);	
	xmlhttp.send();
	return false;
}
function UpdateModule(module_code)
{
	
	var abc = document.getElementById(String(module_code)).value ;
	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			if(xmlhttp.responseText == "-1")
			{
				alert("There was an error during update");
			}
			else if(xmlhttp.responseText == "-2" )
			{
				alert("You did not enter Sort Module");
			}
			else if(xmlhttp.responseText == "-3")
			{
				alert("Sort Module may only enter >=0");
			}
			else if(xmlhttp.responseText == "-4")
			{
				alert("Sequence number already exists");
			}
			else if(xmlhttp.responseText == "-5")
			{
				alert("You don`t have permission to manipulate the Widget Module");
			}
			else if(xmlhttp.responseText == "-6")
			{
				alert("You don`t have permission to manipulate the Page Module");
			}
			else
			{
				alert("update successful");
			}
		}	
	};
	var url = "<?php echo $this->updateUrl;?>?module="+module_code+"&sort="+abc;
	xmlhttp.open("GET",url,true);	
	xmlhttp.send();
	return false;
}
</script>
